package net.azure.app.model;

import java.util.Collection;
import java.util.List;
import java.util.LinkedList;

/**
 * Created by IntelliJ IDEA.
 * User: Venkatraman Kandaswamy : kvenkatraman@gmail.com
 * Date: 12-Jun-2008
 * Time: 06:51:56
 */
public class Estimate implements IModel{
    int minimum;
    int likely;
    int maximum;
    int planned;

    final int minimumPosition = 0;
    final int likelyPosition = 1;
    final int maximumPosition = 2;
    final int plannedPosition = 3;

    public Estimate(int minimum, int likely, int maximum, int planned) {
        this.minimum = minimum;
        this.likely = likely;
        this.maximum = maximum;
        this.planned = planned;
    }

    public Estimate(int offset, String[] columns) {
        minimum = extractValue(minimumPosition+offset, columns);
        likely = extractValue(likelyPosition+offset, columns);
        maximum = extractValue(maximumPosition+offset, columns);
        planned = extractValue(plannedPosition+offset, columns);
    }

    private int extractValue(int offset, String[] columns) {
        try {
            return Integer.parseInt(columns[offset]);
        } catch (NumberFormatException e) {
            return 0;
        }
    }

    @Override
    public Object field(int position) {
        switch(position){
            case minimumPosition : return minimum;
            case likelyPosition : return likely;
            case maximumPosition : return maximum;
            case plannedPosition : return planned;
        }
        return null;
    }

    public int getMinimum() {
        return minimum;
    }

    public void setMinimum(int minimum) {
        this.minimum = minimum;
    }

    public int getLikely() {
        return likely;
    }

    public void setLikely(int likely) {
        this.likely = likely;
    }

    public int getMaximum() {
        return maximum;
    }

    public void setMaximum(int maximum) {
        this.maximum = maximum;
    }

    public int getPlanned() {
        return planned;
    }

    public void setPlanned(int planned) {
        this.planned = planned;
    }

    @Override
    public List<String> header() {
        List<String> header = new LinkedList<String>();
        header.add("Minimum");
        header.add("Likely");
        header.add("Maximum");
        header.add("Planned Estimate");
        return header;
    }

    public static int[] estimateValues(){
        return new int[]{1,2,3,5,8,13,21};
    }
}
